<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>个人信息</title>
<!-- bootstrap样式、主题、核心文档 -->
<link rel="stylesheet" href="../libs/bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="../libs/bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/css/bootstrap-theme.min.css" />
<script type="text/javascript" src="../libs/bootstrap-3.3.7-dist/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../libs/jquery/jquery.js"></script>
<style type="text/css">
	.jumbotron{
		height:400px;
	}
	.btn.btn-danger{
		width:300px;
		font-size: 20px;
	}
	.inner{
		float:left;
		height:300px;
		
		
	}
	#inner2{
		background-color: white;
	}
	
	.container{
		margin-left: 0;
		margin-right: 0;
		width:100%;
	}
	cont{
	width:100px;
	}
</style>
</head>
<body style="padding: 0;">
	
	<div class="jumbotron container">
		<div style="width:40%; margin-left: 85px;" class="inner">
		<form class="form-inline">
		<p><span class="cont">账户余额:</span ><span style="display: inline-block;background-color: LemonChiffon; width: 150px;"></span><button type="button" class="btn btn-success" style="margin-left: 5px; height: 30px;">充值</button>
		</p>
		<p><span class="cont">出借金额:</span><span style="display: inline-block;background-color: LemonChiffon; width: 150px;"></span></p>
		<p><span class="cont">累积收益:</span><span style="display: inline-block;background-color: LemonChiffon; width: 150px;"></span>
		</p>
		
	 	<p><button type="button" class="btn btn-danger">提现</button></p>
		</form>
		</div>
		<div style="width:50%;" class="inner jumbotron" id="inner2">
			<h2><i>投资收益看得见</i></h2>
			<h2>轻松一借，收益进来</h2>
		</div>
	</div>
<script type="text/javascript">
	$(function(){
		userid = "${user.id}";
		//查询余额
		$.ajax({
			type:"post",
			url:"../BalanceSelectServlet",
			data:"userid="+userid,
			dataType:"json",
			success:function(data){
				$("span").eq(1).html("￥"+data.money.toFixed(2));
			}
		});
		//查询出借总金额
		$.ajax({
			type:"post",
			url:"../LendTotalServlet",
			data:"lenderid="+userid,
			dataType:"json",
			success:function(data){
				$("span").eq(3).html("￥"+data.money.toFixed(2));
			}
		});
		
		//充值
		$("button").eq(0).on("click",function(){
			var money=prompt("请输入充值金额");
			if(money==""){
				alert("请输入正确的金额");
			}else{
				//是把充值的金额增加到balance表
				$.post("../BalanceUpdateServlet",{money:money,userid:userid},function(result){
					//充值成功，需要把充值记录添加到recharg表中
					if(result.flag){
						$.post("../RechargeAddServlet",{money:money,userid:userid},function(result2){
							if(result2.flag){
								alert(result.message);
								location.reload();
							}else{
								alert(result.message);
							}
						},"json");
					}else{
						alert(result.message);
					}
				},"json");
			}
			
		});
		
		//提现
		$("button").eq(2).on("click",function(){
			var money=prompt("请输入提现金额");
			if(money==""){
				alert("请输入正确的金额");
			}else{
				//是把充值的金额增加到balance表
				$.post("../BalanceMinusServlet",{money:money,userid:userid},function(result){
					//充值成功，需要把充值记录添加到recharg表中
					if(result.flag){
						$.post("../WithdrawAddServlet",{money:money,userid:userid},function(result2){
							if(result2.flag){
								alert("提现"+result.message);
								location.reload();
							}else{
								alert("提现"+result.message);
							}
						},"json");
					}else{
						alert("提现"+result.message);
					}
				},"json");
			}
			
		});
		
	});
</script>
</body>
</html>